﻿using System;
using System.Web.Mvc;
using LordJS.Exceptions;

namespace LordJS.Filters
{
    [AttributeUsage(AttributeTargets.Method)]
    public sealed class AjaxActionAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!filterContext.HttpContext.Request.IsAjaxRequest())
            {
                throw new UnAuthorizedException();
            }

            base.OnActionExecuting(filterContext);
        }
    }
}